<template>
    <a-form-model
      ref="ruleForm"
      :model="form"
      :rules="rules"
      :label-col="labelCol"
      :wrapper-col="wrapperCol"
    >
      <a-form-model-item ref="name" label="出所时间">
        <a-date-picker
          :disabled="true"
          v-model="form.departureTime"
          valueFormat='YYYY-MM-DD'
          format="YYYY-MM-DD"
          style="width: 100%"
        />
      </a-form-model-item>
      <a-form-model-item label="出所详细地址">
        <a-input
          :disabled="true"
          v-model="form.detailAddress"
          placeholder="请输入出所详细地址"
        />
      </a-form-model-item>
      <a-form-model-item label="通知专干/社工人员" prop="professionSocialWorker">
<!--        <j-select-user-by-dep v-model="form.professionSocialWorkerId" :multi="true" ></j-select-user-by-dep>-->
        <a-input-search
          v-model="form.professionSocialWorker"
          placeholder="请先选择用户"
          readOnly
          unselectable="on"
          :disabled="disabled"
          @search="onSearchDepUser">
          <a-button slot="enterButton" :disabled="disabled">选择专干社工</a-button>
        </a-input-search>
      </a-form-model-item>
      <a-form-model-item label="通知内容" prop="noticeContent">
        <a-input v-model="form.noticeContent" type="textarea" />
      </a-form-model-item>
      <a-form-model-item :wrapper-col="{ span: 14, offset: 4 }" v-if="buttonTF">
        <a-button @click="runtenFun">
          返回
        </a-button>
        <a-button style="margin-left: 10px;" type="primary" @click="onSubmit">
          确认通知
        </a-button>
        <a-button style="margin-left: 10px;" @click="localStorageFun">
          保存并退出
        </a-button>
      </a-form-model-item>
      <suoerviseJmodal ref="suoerviseJmodal" @ok="modalFormOk"></suoerviseJmodal>
    </a-form-model>
</template>

<script>
/*
通知
 */
import Vue from "vue";
import {USER_INFO} from "@/store/mutation-types";
import suoerviseJmodal from "@views/sjsk/management/join/supervise/suoerviseJmodal";
import {
  noticePersonOffice,
  notifyUnit,
  queryNoticePersonOffice,
  queryPersonReceive,
  queryUnit
} from "@api/sjsk/receiveCase";

export default {
  name: "notice",
  props:['current'],
  components:{suoerviseJmodal},
  data(){
    return {
      descriptions:this.$route.query,
      form:{
        professionSocialWorker:'',
        departureTime:'2023-3-1',
        detailAddress:'1231231'
      },
      buttonTF:true,
      disabled:false,
      labelCol: { span: 4 },
      wrapperCol: { span: 8 },
      rules:{
        professionSocialWorker:[{ required: true, message: '请选择专干/社工', trigger: 'blur' }],
        noticeContent:[{ required: true, message: '请输入通知内容', trigger: 'blur' }],
      },
      orgCode:''
    }
  },
  created() {
    this.orgCode = Vue.ls.get(USER_INFO).orgCode
    console.log(this.orgCode)

  },
  mounted() {
    this.form.id = this.$route.query.id
    console.log(this.$route.query)
    this.queryFun(this.$route.query.personId)
    this.buttonTF = this.current === 3
    // console.log(this.$store.state.holographicArchives.currentStage)
    this.disabled = !this.buttonTF
    // if(localStorage.getItem('noticeeForm')){
    //   this.form = JSON.parse(localStorage.getItem('noticeeForm'))
    // }
  },
  methods:{
    professionSocialWorkerIdfun(val){
      this.form.professionSocialWorkerId = val.id
    },
    //选择专干社工
    onSearchDepUser(){
      this.$refs.suoerviseJmodal.showAdminFun()
    },
    //查询
    queryFun(val){
      queryPersonReceive({id:val}).then(ser => {
        if(ser.success && ser.result){
          console.log(ser)
          this.form = ser.result.noticeProfessionSocialWorker
          console.log(this.form)
        }
      }).catch(err => {
        console.log(err)
      })
    },
    //返回
    runtenFun(){
      this.$router.go (-1)
    },
    //提交
    onSubmit() {
      console.log(this.form)
      this.form = Object.assign(this.form,{id:this.$route.query.id},{personId:this.$route.query.personId})
      // delete this.form.professionSocialWorker
      this.$refs.ruleForm.validate(valid => {
        if (valid) {
          noticePersonOffice(this.form).then(ser => {
            if(ser.success){
              this.disabled = true
              this.buttonTF = false
              this.$emit('currentFu',4)
              // this.$route.query.currentStage = 1
              // this.$store.dispatch('currentStage',1)
              this.$message.success('通知成功')
            }
          })
        } else {
          this.$message.warn('请检查你的数据')
          return false;
        }
      });
    },
    modalFormOk(val) {
      console.log(val)
      this.form.professionSocialWorker = val.professionalsWorker
      this.form.professionSocialWorkerId = val.professionalsWorkerId
    },
    //半永久存储
    localStorageFun(){
      this.$refs.ruleForm.validate(valid => {
        if (valid) {
          //本地永久存储
          localStorage.setItem('noticeeForm',JSON.stringify(this.form))
        } else {
          this.$message.warn('请检查你的数据')
          return false;
        }
      });

    }
  }
}
</script>

<style scoped>

</style>